import torch

out = torch.randn(200,10)
y = torch.LongTensor(np.random.randint(0,10,200)) #必须是LongTensor类型的
print(out.size(),y.size(),out.dtype,y.dtype)
criterion = torch.nn.CrossEntropyLoss()
loss = criterion(out, y) #y不能用one-hot编码，要用类标值

#损失函数类型：
CrossEntropyLoss #分类问题
BCELoss(weight=None, size_average=None, reduce=None, reduction='mean') #二分类问题
L1Loss(size_average=None, reduce=None, reduction='mean') #L1 norm
MSELoss #L2 norm
